package com.MovieManageSystem.controller;

import com.MovieManageSystem.domain.User;
import com.MovieManageSystem.entity.Result;
import com.MovieManageSystem.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
@CrossOrigin(origins = "*")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping
    public Result getUserList(User user){
        List<User> userList = userService.getUserList(user);
        return Result.success(userList);
    }
    /**
     * 新增用户
     */
    @PostMapping
    public Result add(@RequestBody User user)
    {
        userService.insertUser(user);
        return Result.success();
    }

    /**
     * 修改用户
     */
    @PutMapping
    public Result updateUser(@RequestBody User user)
    {
        userService.updateUser(user);
        System.out.println(user.toString());
        return Result.success();
    }

    /**
     * 删除用户
     */
    @DeleteMapping("/{uids}")
    public Result remove(@PathVariable Long[] uids)
    {
        userService.deleteUserByUids(uids);
        return Result.success();
    }
}
